package com.tadpole.music.adapter.study;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;

import com.tadpole.music.R;
import com.tadpole.music.adapter.base.BaseAdapter;
import com.tadpole.music.bean.study.ExaminationErrorListBean;
import com.tadpole.music.holder.base.BaseViewHolder;
import com.tadpole.music.holder.base.NoDataEmpty;
import com.tadpole.music.holder.study.ExaminationErrorViewHolder;
import com.tadpole.music.holder.study.ExamsViewHolder;

import java.util.List;

/**
 * Created By 孙岩
 * on 2020/10/10
 */
public class ExaminationErrorAdapter extends BaseAdapter {
    private Activity activity;
    private ExaminationErrorViewHolder examinationErrorViewHolder;
    private OnChildClickListener onChildClickListener;
    private List<ExaminationErrorListBean.DataBeanX.DataBean> list;
    private OnItemClickListener onItemClickListener;
    private String flag;
    public ExaminationErrorAdapter(Activity activity, List<ExaminationErrorListBean.DataBeanX.DataBean> list, String flag) {
        this.activity = activity;
        this.list = list;
        this.flag = flag;
    }

    @Override
    public BaseViewHolder createRelHolder(ViewGroup parent, int viewType) {
        if (list == null || list.size() == 0) {
            String empty = "NO_DATA";
            LayoutInflater layoutInflater = LayoutInflater.from(activity);
            View inflate = layoutInflater.inflate(R.layout.item_no_data, parent, false);
            NoDataEmpty noDataEmpty = new NoDataEmpty(inflate, empty);
            return noDataEmpty;
        } else {
            examinationErrorViewHolder = new ExaminationErrorViewHolder(activity,LayoutInflater.from(activity).inflate(R.layout.item_examination_error, parent, false), onItemClickListener,onChildClickListener,list,flag);
            return examinationErrorViewHolder;
        }
    }

    @Override
    public int getRelItemCount() {
        return list == null || list.size() == 0 ? 1 : list.size();
    }

    @Override
    public void setOnItemClickListener(OnItemClickListener listener) {
        this.onItemClickListener = listener;
    }

    @Override
    public void setOnChildClickListener(OnChildClickListener listener) {
        this.onChildClickListener = listener;
    }

    @Override
    public void setOnLongClickListener(OnLongClickListener listener) {

    }

    @Override
    public void onBindViewHolder(@NonNull BaseViewHolder holder, int position) {
        holder.init(position - mHeadViews.size());
    }
}
